<?php
namespace app\index\controller;
use think\Session;

use Think\Controller;
use think\Request;


class Policy  extends \think\Controller {
	public function policy_list() {
		return $this -> fetch();
	}

	//航运新闻数据
	public function policy_con() {
		$list = \think\Db::table('course_info') -> select();
		
		//获取用户名
		$username = Session::get('username');
		//获取学生信息
		$stu_info = \think\Db::table('bk_admin') -> where('username',$username)->find();
		//学生学位
		$stu_degree = $stu_info['DegreeRequirement'];
		//学生专业
		$program = $stu_info['Program'];
		//学生学期
		$semester = $stu_info['semester'];
		$premodule = $stu_info['Premodule'];
		$course = \think\Db::table('course_info') ->select();
	
		
		
		
		//获取数据总条数
		$count = count($list);
		//获取每页显示的条数
		$limit = Request::instance()->param('limit');
		//获取当前页数
		 $page= Request::instance()->param('page');
	
		$rs = \think\Db::table('course_info') -> where('DegreeRequirement',$stu_degree)
		->where('ProgramRequirement',$program)
		->where('semester',$semester)
		-> limit( ($page-1)*$limit,$limit )
		->select();
		
		
		 return ["code"=>"0","msg"=>"","data"=>$rs,"count"=>$count];
		
	}
	
//	//航运新闻数据修改
	public function policy_modify() {
		$this->local_hash =  $_SERVER['QUERY_STRING'];
		$hash = $this->local_hash;
		Session::set('id', $hash);
		
		$risk_list = \think\Db::table('gat_policy')->where('id', $hash)->find();
		
		$policy_tit = $risk_list ['title'];
		$policy = $risk_list ['policy'];
		$this->assign('policy_tit',$policy_tit);
        $this->assign('policy',$policy);
		
		return $this -> fetch();
		
	}
//	
//	//更新新闻数据
	public function  policy_update() {
		
		$session_name = Session::get('id');
		 
		if (Request::instance()->isPost()){
			
			$data = ['title' => $_POST['policy_tit'], 'policy' => $_POST['policy']];
			
			\think\Db::name('gat_policy')->where('id', $session_name)->update($data);	
			
		} 
	}
//	
//	//新增航运新闻数据
	public function policy_add() {
		return $this -> fetch();
	}
//	
//	//插入新增新闻数据
	public function policy_insert() {
			if (Request::instance()->isPost()){
					$data = ['title' => $_POST['news_title'], 'policy' => $_POST['news_content']];
				\think\Db::name('gat_policy')->insert($data);	
				} 
	}
//	
	//新闻数据删除
	public function policy_del(Request $request) {
		$request = Request::instance();
		if($request -> method() == 'POST'){
			$id = $_POST['id'];
			\think\Db::table('gat_policy')->where('id',$id)->delete();
		}else{
			return '请使用post提交';
		}
	}
	
//	//新闻模糊搜索
//	public function fuzzy_query() {
//		if (Request::instance()->isPost()){
//			//$key  = $_POST['name'];
//			\think\Db::table('gat_news')->where('title',['like','%1%'])->find();
////					$data = ['title' => $_POST['news_title'], 'news' => $_POST['news_content']];
////				\think\Db::name('gat_news')->insert($data);	
//		} 
//	}
}
?>